package vg.modules.search;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Observable;
import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;
import vg.core.AMenuItem;
import vg.core.event.AUIEvent;
import vg.core.event.UIEventChangeView;
import vg.core.event.UIEventOpenNewGraph;
import vg.core.exception.PluginException;
import vg.core.plugin.IPlugin;
import vg.core.plugin.PluginParameter;
/**
* This class for search of vertexes.
* @author tzolotuhin
*/
public class SearchPlugin implements IPlugin {
private PluginParameter parameter; // plugin parameter
private JMenuItem jMenuItem;
private SearchPanel searchPanel;
/**
* @see IPlugin
*/
public void install(final PluginParameter param) throws PluginException {
this.parameter = param;
//---------------------------------------
this.searchPanel = new SearchPanel("Search panel", param);
this.jMenuItem = new JMenuItem("Search");
this.jMenuItem.setIcon(new ImageIcon("./data/resources/textures/search.png"));
this.jMenuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
SearchPlugin.this.searchPanel.open();
}
});
this.jMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK));
this.parameter.userInterface.addMenuItem(new AMenuItem(this.jMenuItem) {
public void update(Observable o, Object arg) {
if(arg instanceof AUIEvent) {
final AUIEvent event = (AUIEvent)arg;
switch (event.getType()) {
case DEF_CLOSE_PROGRAM: {
SearchPlugin.this.searchPanel.dispose();
break;
}
case DEF_OPEN_NEW_GRAPH: {
UIEventOpenNewGraph buf = (UIEventOpenNewGraph)event;
SearchPlugin.this.searchPanel.addGraph(buf.getGraphId(), buf.getGraphName());
break;
}
case DEF_CHANGE_UI_STYLE: {
SearchPlugin.this.searchPanel.updateUITheme();
break;
}
case DEF_CHANGE_VIEW: {
UIEventChangeView buf = (UIEventChangeView)event;
SearchPlugin.this.searchPanel.changeView(buf.getView());
break;
}
case DEF_RESET: {
SearchPlugin.this.searchPanel.reset();
break;
}
}
}
}
}, "edit");
this.searchPanel.updateUITheme();
}
}